<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <style>
    * {
      margin: 0;
      padding: 0;
    }
    .box {
      width: 100%;
      height: 400px;
    }
  </style>
  <body>
    <div class="box"></div>
  </body>
  <script src="https://cdn.bootcdn.net/ajax/libs/echarts/5.1.2/echarts.js"></script>
  <script>
    // 基于准备好的dom，初始化echarts实例
    let dom = document.querySelector(".box");
    //创建实例
    let myCharts = echarts.init(dom);
    myCharts.setOption({
      //放大数据
      dataZoom: {},
      title: {
        text: "echarts组件",
      },
      xAxis: {
        data: ["游戏", "电影", "直播", "娱乐"],
      },
      yAxis: {},
      series: [
        {
          name: "柱状图",
          type: "bar",
          data: [20, 30, 40, 50],
        },
        {
          name: "折线图",
          type: "line",
          data: [30, 40, 50, 60],
        },
      ],
      //提示组件
      tooltip: {
        //提示框文字颜色
        textStyle: {
          color: "red",
        },
      },
      //系列切换，这里面的data要和每个series对象的name属性去使用
      legend: {
        data: ["柱状图", "折线图"],
      },
      //工具栏组件,顺序可以调整
      toolbox: {
        show: true,
        feature: {
          dataZoom: {
            yAxisIndex: "none",
          },
          dataView: {
            readOnly: false,
          },
          magicType: {
            type: ["line", "bar"],
          },
          restore: {},
          saveAsImage: {},
        },
      },
      //调整图表布局,类似于css的margin,相对于父容器的位置
      grid:{
          left:30,
          right:0
      }
    });
  </script>
</html>
